/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.saber.certificacao.modelos.relacionamentos;

import br.com.saber.certificacao.modelos.Usuario;
import br.com.saber.certificacao.modelos.Versao;
import br.com.saber.certificacao.modelos.relacionamentos.idcompostos.IdProfessorVersaoPk;
import java.io.Serializable;
import javax.persistence.*;

/**
 *
 * @author gbvbahia
 */
@Entity
@Table(name = "professor_versao")
public class ProfessorVersao implements Serializable, Comparable<ProfessorVersao> {

    @EmbeddedId
    private IdProfessorVersaoPk id = new IdProfessorVersaoPk();

    @ManyToOne(targetEntity = br.com.saber.certificacao.modelos.Usuario.class)
    @JoinColumn(name = "aluno_id", referencedColumnName = "id", insertable = false, updatable = false)
    private Usuario professor;

    @ManyToOne(targetEntity = br.com.saber.certificacao.modelos.Versao.class)
    @JoinColumn(name = "versao_id", referencedColumnName = "id", insertable = false, updatable = false)
    private Versao versao;

    public ProfessorVersao() {
    }

    public ProfessorVersao(Usuario professor, Versao versao) {
        this.professor = professor;
        this.versao = versao;
        this.id = new IdProfessorVersaoPk(professor.getId(), versao.getId());
    }

    public IdProfessorVersaoPk getId() {
        return id;
    }

    public void setId(IdProfessorVersaoPk id) {
        this.id = id;
    }

    public Usuario getProfessor() {
        return professor;
    }

    public void setProfessor(Usuario professor) {
        this.professor = professor;
    }

    public Versao getVersao() {
        return versao;
    }

    public void setVersao(Versao versao) {
        this.versao = versao;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ProfessorVersao other = (ProfessorVersao) obj;
        if (this.professor != other.professor && (this.professor == null || !this.professor.equals(other.professor))) {
            return false;
        }
        if (this.versao != other.versao && (this.versao == null || !this.versao.equals(other.versao))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.professor != null ? this.professor.hashCode() : 0);
        return hash;
    }

    @Override
    public int compareTo(ProfessorVersao o) {
        int toReturn = professor.compareTo(o.getProfessor());
        if(toReturn == 0){
            toReturn = versao.compareTo(o.getVersao());
        }
        return toReturn;
    }
}
